/******************************************************************************
 * (C) Copyright 2013 Atech-Automotive
 * FILE NAME:    uds_diag_config.c
 * DESCRIPTION:
 *
 * DATE BEGUN:   2015/05/05
 * BY:           hui.pang
 * PRODUCT NAME:
 * APPLICATION:
 * TARGET H/W:
 * DOC REF:
 *****************************************************************************
 */

/*****************************************************************************
** #include
*****************************************************************************/
#include "system.h"
#include "uds_diag_appl.h"
#include "uds_diag_config.h"
#include "uds_diag_interface.h"

//#include "hwa_a2dActions.h"
#include  "hwa_inputs_cfg.h"
/*****************************************************************************
** #define
*****************************************************************************/


/*****************************************************************************
** typedef
*****************************************************************************/


/*****************************************************************************
** global variable
*****************************************************************************/

/*
**  Global Var:  c_u32_can_tx_diag_id
**  Description:
**
**  Author:      2015/05/05, hui.pang create this Variable
*/
const UINT32 c_u32_can_tx_diag_id = 0x70C;//0x7FB;

/*
**  Global Var:  c_u32_can_rx_diag_id
**  Description:
**
**  Author:      2015/05/05, hui.pang create this Variable
*/
const UINT32 c_u32_can_rx_diag_id = 0x704;//0x7FA;
/*
**  Global Var:  c_u32_can_rx_diag_id
**  Description: 
**               
**  Author:      2017/02/22, hui.liu create this Variable
*/
const UINT32 c_u32_can_rx_fun_diag_id = 0x7DF;


const BOOL c_b_diag_stop_low_or_high_vbat = FALSE;

const UINT8 c_u8_diag_low_vbat_th = VBAT_6_5V;
const UINT8 c_u8_diag_high_vbat_th = VBAT_16_5V;

const UINT16 c_u16_diag_low_vbat_off_time = 0;
const UINT16 c_u16_diag_low_vbat_recover_time = 150;
const UINT16 c_u16_diag_high_vbat_off_time = 0;
const UINT16 c_u16_diag_high_vbat_recover_time = 150;


#ifdef MODE_10_SUPPORTED

/*
**  Global Var:  c_u16_p2can_server_max
**               c_u16_p2xcan_server_max
**  Description: uds 0x10 service response session parameter record
**               
**  Author:      2016/08/12, hui.liu create this Variable
*/
const UINT16 c_u16_p2can_server_max                     = 50;      /* P2CAN_Server max: 50 ms */
const UINT16 c_u16_p2xcan_server_max                    = 500;     /* P2*CAN_Server max: 500 ms@10ms */

/*
**  Global Var:  c_b_0x10_support_default_to_pragram
**  Description:FALSE:not support  TRUE:support
**               
**  Author:      2016/12/08, lele.zhu create this Variable
*/

const BOOL c_b_0x10_support_default_to_pragram = FALSE;

#endif

#ifdef MODE_11_SUPPORTED

/*
**  Global Var:  c_u8_0x11_ecu_reset_time
**  Description: ecu reset delay time
**               
**  Author:      2016/08/12, hui.liu create this Variable
*/
const UINT8 c_u8_0x11_ecu_reset_time                    = 10;          /* 10 * 10ms = 100ms  */


#endif

#ifdef MODE_14_SUPPORTED

const UINT8  c_b_0x14_diag_support_clear_single_dtc = FALSE;

#endif  /* MODE_14_SUPPORTED */


#ifdef MODE_27_SUPPORTED

/*
**  Global Var:  c_u8_0x27_access_seed_lenght
**  Description: uds access random number length
**               
**  Author:      2016/08/12, hui.liu create this Variable
*/
const UINT8 c_u8_0x27_access_seed_lenght                = 0x02;

/*
**  Global Var:  c_u8_0x27_access_diag_init_timer
**  Description: power on access diag delay time, n*1s forbit security access
**               
**  Author:      2016/08/12, hui.liu create this Variable
*/
const UINT8 c_u8_0x27_access_diag_init_timer            = 0;

/*
**  Global Var:  c_u8_access_invalid_attempt_counter
**  Description: After every c_u8_access_invalid_attempt_counter continuous 
**           failed attempts of security access by the tester, 
**           the ECU will be locked to attempt for c_u16_0x27_access_retry_time_interval
**           more seconds added to the last locked time
**               
**  Author:      2016/08/16, hui.liu create this Variable
*/
const UINT8 c_u8_access_invalid_attempt_counter         = 2;    /*  */

/*
**  Global Var:  c_u16_0x27_access_retry_time_interval
**  Description: access retry error lock time
**               
**  Author:      2016/08/16, hui.liu create this Variable
*/
const UINT16 c_u16_0x27_access_retry_time_interval      = 10;   /* n*1s */

/*
**  Global Var:  c_u16_0x27_access_retry_time_interval_max
**  Description: the max value of error interval counter
**               
**  Author:      2016/08/16, hui.liu create this Variable
*/
const UINT16 c_u16_0x27_access_retry_time_interval_max  = 1000; /* n*1s */

#endif

#ifdef MODE_28_SUPPORTED


#endif

#ifdef MODE_2F_SUPPORTED

/****************************************************************************/
/**
 * Function Name: c_b_0x2F_cmd_return_to_ecu_cmd_enable
 *                c_b_0x2F_cmd_reset_to_default_cmd_enable
 *                c_b_0x2F_cmd_freeze_current_state_cmd_enable
 *                c_b_0x2F_cmd_short_term_adjustment_enable
 * Description: uds io ctrl parameter enable, return NRC31 if parameter is false
 *
 * Param:   none
 * Return:  none
 * Author:  2016/08/16, hui.liu create this function
 ****************************************************************************/
const BOOL c_b_0x2F_cmd_return_to_ecu_cmd_enable        = TRUE;
const BOOL c_b_0x2F_cmd_reset_to_default_cmd_enable     = FALSE;
const BOOL c_b_0x2F_cmd_freeze_current_state_cmd_enable = FALSE;
const BOOL c_b_0x2F_cmd_short_term_adjustment_enable    = TRUE;

#endif

#ifdef MODE_23_SUPPORTED

const BOOL c_b_0x23_sec_levels                          = _SEC_NONE_MODE;

#endif

#ifdef MODE_3D_SUPPORTED

const BOOL c_b_0x3D_sec_levels                          = _SUPP_ACCESS_09;

#endif

/*
**  Global Var:  c_s_udsServiceConfig
**  Description: uds service cmd length and support access type config
**               can not delete the last line {0xFF , 0xFF , 0xFF}
**  Author:      2016/08/12, hui.liu create this Variable
*/
const UdsServiceConfig_S c_s_udsServiceConfig[] =
{
    { ENTRDIAG       , 0x02 ,              ALL_SUPPORT },
    { ECURESET       , 0x02 ,              ALL_SUPPORT },
    { TSTRPRNT       , 0x02 ,              ALL_SUPPORT },
    { SECACCESS      , 0x02 | LENGTH_MIN , EXT_PHYS    },
    { RDBYID         , 0x03 ,              ALL_SUPPORT },
    { WRBYID         , 0x03 | LENGTH_MIN , EXT_PHYS    },
    { DTCINFO        , 0x02 | LENGTH_MIN , ALL_SUPPORT },
    { CLRDTCRQ       , 0x04 ,              ALL_SUPPORT },
    { ROUTINECTRL    , 0x04 | LENGTH_MIN , EXT_PHYS    },
    { IOCTRLBYID     , 0x04 | LENGTH_MIN , EXT_PHYS    },
    { COMMCTRL       , 0x03 ,              EXT_SUPPORT },
    { DTCSETTINGCTRL , 0x02 ,              EXT_SUPPORT },
    { RDMBYADDR      , 0x04 | LENGTH_MIN , ALL_SUPPORT },
    { WRMBYADDR      , 0x04 | LENGTH_MIN , ALL_SUPPORT },
    { 0xFF           , 0xFF ,              0xFF},//can not delete this line
};

/*
**  Global Var:  c_s_uds0x10SubFunctionConfig
**  Description: uds sub function length and support access type config
**               can not delete the last line {0xFF , 0xFF , 0xFF}
**  Author:      2016/08/12, hui.liu create this Variable
*/
const UdsSubFunction_S c_s_uds0x10SubFunctionConfig[] =
{
    { 0x01 , 0x02 , ALL_SUPPORT},
    { 0x02 , 0x02 , ALL_SUPPORT},
    { 0x03 , 0x02 , ALL_SUPPORT},
    { 0x81 , 0x02 , ALL_SUPPORT},
    { 0x82 , 0x02 , ALL_SUPPORT},
    { 0x83 , 0x02 , ALL_SUPPORT},
    { 0xFF , 0xFF , 0xFF},//can not delete this line
};

/*
**  Global Var:  c_s_uds0x11SubFunctionConfig
**  Description: uds sub function length and support access type config
**               can not delete the last line {0xFF , 0xFF , 0xFF}
**  Author:      2016/08/12, hui.liu create this Variable
*/
const UdsSubFunction_S c_s_uds0x11SubFunctionConfig[] =
{
    { 0x01 , 0x02 , ALL_SUPPORT},
//    { 0x02 , 0x02 , ALL_SUPPORT},
//    { 0x03 , 0x02 , ALL_SUPPORT},
    { 0x81 , 0x02 , ALL_SUPPORT},
//    { 0x82 , 0x02 , ALL_SUPPORT},
//    { 0x83 , 0x02 , ALL_SUPPORT},
    { 0xFF , 0xFF , 0xFF},//can not delete this line
};

#ifdef MODE_19_SUPPORTED

/*
**  Global Var:  c_u8_0x19_dtc_supported_mask
**  Description: uds service $19 supported mask
**               
**  Author:      2016/10/10, hui.liu create this Variable
*/
const UINT8 c_u8_0x19_dtc_supported_mask = 0x09;//DTC_STATUS_SUPPORTED_MASK;

/*
**  Global Var:  c_s_uds0x19SubFunctionConfig
**  Description: uds sub function length and support access type config
**               can not delete the last line {0xFF , 0xFF , 0xFF}
**  Author:      2016/08/12, hui.liu create this Variable
*/
const UdsSubFunction_S c_s_uds0x19SubFunctionConfig[] =
{
    { 0x01 , 0x03 , ALL_SUPPORT},
    { 0x02 , 0x03 , ALL_SUPPORT},
    { 0x04 , 0x06 , PHYS_SUPPORT},
    { 0x06 , 0x06 , PHYS_SUPPORT},
    { 0x0A , 0x02 , ALL_SUPPORT},
    { 0xFF , 0xFF , 0xFF},//can not delete this line
};

#endif

/*
**  Global Var:  c_s_uds0x27SubFunctionConfig
**  Description: uds sub function length and support access type config
**               can not delete the last line {0xFF , 0xFF , 0xFF}
**  Author:      2016/08/12, hui.liu create this Variable
*/
const UdsSubFunction_S c_s_uds0x27SubFunctionConfig[] =
{
    { 0x01 , 0x02 , EXT_PHYS},
    { 0x02 , 0x04 , EXT_PHYS},
    { 0x03 , 0x02 , EXT_PHYS},
    { 0x04 , 0x04 , EXT_PHYS},
    { 0x05 , 0x02 , EXT_PHYS},
    { 0x06 , 0x04 , EXT_PHYS},
//    { 0x07 , 0x02 , EXT_PHYS},
//    { 0x08 , 0x06 , EXT_PHYS},
//    { 0x09 , 0x02 , EXT_PHYS},
//    { 0x0A , 0x04 , EXT_PHYS},
    { 0xFF , 0xFF , 0xFF},//can not delete this line
};

#ifdef MODE_28_SUPPORTED

/*
**  Global Var:  c_s_uds0x28SubFunctionConfig
**  Description: uds sub function length and support access type config
**               can not delete the last line {0xFF , 0xFF , 0xFF}
**  Author:      2016/08/12, hui.liu create this Variable
*/
const UdsSubFunction_S c_s_uds0x28SubFunctionConfig[] =
{
    { 0x00 , 0x03 , EXT_SUPPORT},
    { 0x03 , 0x03 , EXT_SUPPORT},
    { 0x80 , 0x03 , EXT_SUPPORT},
    { 0x83 , 0x03 , EXT_SUPPORT},
    { 0xFF , 0xFF , 0xFF},//can not delete this line
};

#endif

/*
**  Global Var:  c_s_uds0x31SubFunctionConfig
**  Description: uds sub function length and support access type config
**               can not delete the last line {0xFF , 0xFF , 0xFF}
**  Author:      2016/08/12, hui.liu create this Variable
*/
const UdsSubFunction_S c_s_uds0x31SubFunctionConfig[] =
{
    { 0x01 , 0x04 | LENGTH_MIN , EXT_PHYS},
    { 0x02 , 0x04 | LENGTH_MIN , EXT_PHYS},
    { 0x03 , 0x04 , EXT_PHYS},
    { 0xFF , 0xFF , 0xFF},//can not delete this line
};

/*
**  Global Var:  c_s_uds0x3ESubFunctionConfig
**  Description: uds sub function length and support access type config
**               can not delete the last line {0xFF , 0xFF , 0xFF}
**  Author:      2016/08/12, hui.liu create this Variable
*/
const UdsSubFunction_S c_s_uds0x3ESubFunctionConfig[] =
{
    { 0x00 , 0x02 , ALL_SUPPORT},
    { 0x80 , 0x02 , ALL_SUPPORT},
    { 0xFF , 0xFF , 0xFF},//can not delete this line
};

#ifdef MODE_85_SUPPORTED

/*
**  Global Var:  c_s_uds0x85SubFunctionConfig
**  Description: uds sub function length and support access type config
**               can not delete the last line {0xFF , 0xFF , 0xFF}
**  Author:      2016/08/12, hui.liu create this Variable
*/
const UdsSubFunction_S c_s_uds0x85SubFunctionConfig[] =
{
    { 0x01 , 0x02 , EXT_SUPPORT},
    { 0x02 , 0x02 , EXT_SUPPORT},
    { 0x81 , 0x02 , EXT_SUPPORT},
    { 0x82 , 0x02 , EXT_SUPPORT},
    { 0xFF , 0xFF , 0xFF},//can not delete this line
};
#endif


/*****************************************************************************
** static variables
*****************************************************************************/


/*****************************************************************************
** static constants
*****************************************************************************/


/*****************************************************************************
** static function prototypes
*****************************************************************************/


/*****************************************************************************
** function prototypes
*****************************************************************************/


/****************************************************************************/


/*****************************************************************************
** End File
*****************************************************************************/

